package com.sales.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sales.dao.SalesSlipDetMapper;
import com.sales.service.SalesSlipDetService;
import org.comple.erp.pojo.sales.SalesSlip;
import org.comple.erp.pojo.sales.SalesSlipDet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class SalesSlipDetServiceImpl implements SalesSlipDetService {
    @Autowired
    private SalesSlipDetMapper salesSlipDetMapper;
    @Override
    public Boolean insertSelective(SalesSlipDet record) {
        if(salesSlipDetMapper.insertSelective(record)>0){
            return true;
        }
        return false;
    }

    @Override
    public List<SalesSlipDet> selectBySalesSlipCode(Map<String, Object> params) {
        List<SalesSlipDet> salesSlipList = salesSlipDetMapper.selectBySalesSlipCode(params);
        return salesSlipList;
    }

    @Override
    public Boolean deleteByCode(Map<String, Object>  params) {
        if(salesSlipDetMapper.deleteByCode(params) > 0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean deleteByCodeLj(Map<String, Object>  params) {
        if(salesSlipDetMapper.deleteByCodeLj(params) > 0){
            return true;
        }
        return false;
    }


    @Override
    public PageInfo<SalesSlipDet> selectSlipDetList(Map<String, Object> params) {
        String pageNumStr = (String) params.get("pageNum");
        String pageSizeStr = (String) params.get("pageSize");

        int pageNum = pageNumStr != null && !pageNumStr.isEmpty() ? Integer.parseInt(pageNumStr) : 1;
        int pageSize = pageSizeStr != null && !pageSizeStr.isEmpty() ? Integer.parseInt(pageSizeStr) : 5;
        PageHelper.startPage(pageNum, pageSize);
        List<SalesSlipDet> salesSlipList = salesSlipDetMapper.selectSlipDetList(params);
        PageInfo<SalesSlipDet> pageInfo = new PageInfo<>(salesSlipList);
        return pageInfo;
    }
}
